load("//bazel:ray.bzl", "ray_cc_binary", "ray_cc_library")

ray_cc_library(
    name = "agent_manager",
    srcs = ["agent_manager.cc"],
    hdrs = ["agent_manager.h"],
    visibility = ["//visibility:private"],
    deps = [
        "//src/ray/common:id",
        "//src/ray/common:ray_config",
        "//src/ray/protobuf:gcs_cc_proto",
        "//src/ray/util:event",
        "//src/ray/util:logging",
        "//src/ray/util:process",
        "//src/ray/util:thread_utils",
        "@boost//:asio",
    ],
)

ray_cc_library(
    name = "lease_dependency_manager",
    srcs = ["lease_dependency_manager.cc"],
    hdrs = ["lease_dependency_manager.h"],
    visibility = [":__subpackages__"],
    deps = [
        "//src/ray/common:id",
        "//src/ray/object_manager",
        "//src/ray/util:counter_map",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/container:flat_hash_set",
    ],
)

# TODO(edoakes): looks like this belongs under scheduling/...
ray_cc_library(
    name = "local_lease_manager",
    srcs = ["local_lease_manager.cc"],
    hdrs = ["local_lease_manager.h"],
    visibility = [":__subpackages__"],
    deps = [
        ":lease_dependency_manager",
        ":worker_interface",
        ":worker_pool",
        "//src/ray/common:lease",
        "//src/ray/common:ray_object",
        "//src/ray/common/scheduling:cluster_resource_data",
        "//src/ray/common/scheduling:placement_group_util",
        "//src/ray/object_manager:object_manager_common",
        "//src/ray/raylet/scheduling:cluster_resource_scheduler",
        "//src/ray/raylet/scheduling:local_lease_manager_interface",
        "//src/ray/raylet/scheduling:scheduler_internal",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/container:flat_hash_set",
    ],
)

ray_cc_library(
    name = "placement_group_resource_manager",
    srcs = ["placement_group_resource_manager.cc"],
    hdrs = ["placement_group_resource_manager.h"],
    visibility = [":__subpackages__"],
    deps = [
        "//src/ray/common:id",
        "//src/ray/gcs_rpc_client:gcs_client",
        "//src/ray/raylet/scheduling:cluster_resource_scheduler",
        "//src/ray/util:container_util",
        "@com_google_absl//absl/container:flat_hash_map",
    ],
)

ray_cc_library(
    name = "wait_manager",
    srcs = ["wait_manager.cc"],
    hdrs = ["wait_manager.h"],
    visibility = [":__subpackages__"],
    deps = [
        "//src/ray/common:id",
        "//src/ray/util:container_util",
    ],
)

ray_cc_library(
    name = "worker_interface",
    hdrs = ["worker_interface.h"],
    visibility = [":__subpackages__"],
    deps = [
        "//src/ray/common:id",
        "//src/ray/util:process",
        "@com_google_absl//absl/time",
    ],
)

ray_cc_library(
    name = "worker",
    srcs = ["worker.cc"],
    hdrs = ["worker.h"],
    visibility = [":__subpackages__"],
    deps = [
        ":worker_interface",
        "//src/ray/common:id",
        "//src/ray/common:lease",
        "//src/ray/core_worker_rpc_client:core_worker_client",
        "//src/ray/flatbuffers:node_manager_generated",
        "//src/ray/protobuf:core_worker_cc_grpc",
        "//src/ray/protobuf:core_worker_cc_proto",
        "//src/ray/raylet/scheduling:cluster_resource_scheduler",
        "//src/ray/raylet_ipc_client:client_connection",
        "//src/ray/util:process",
        "@com_google_absl//absl/time",
    ],
)

ray_cc_library(
    name = "fake_worker",
    hdrs = ["fake_worker.h"],
    visibility = [":__subpackages__"],
    deps = [
        ":worker",
        "//src/ray/raylet_ipc_client:client_connection",
    ],
)

ray_cc_library(
    name = "worker_pool",
    srcs = ["worker_pool.cc"],
    hdrs = ["worker_pool.h"],
    visibility = [":__subpackages__"],
    deps = [
        ":runtime_env_agent_client",
        ":worker_interface",
        "//src/ray/common:constants",
        "//src/ray/common:lease",
        "//src/ray/common:protobuf_utils",
        "//src/ray/common:ray_config",
        "//src/ray/common:runtime_env",
        "//src/ray/common:status",
        "//src/ray/core_worker_rpc_client:core_worker_client_interface",
        "//src/ray/gcs_rpc_client:gcs_client",
        "//src/ray/protobuf:core_worker_cc_proto",
        "//src/ray/raylet_ipc_client:client_connection",
        "//src/ray/util:container_util",
        "//src/ray/util:network_util",
        "//src/ray/util:time",
        "@boost//:system",
        "@com_google_absl//absl/strings",
    ],
)

ray_cc_library(
    name = "runtime_env_agent_client",
    srcs = ["runtime_env_agent_client.cc"],
    hdrs = ["runtime_env_agent_client.h"],
    visibility = [":__subpackages__"],
    deps = [
        "//src/ray/common:asio",
        "//src/ray/common:id",
        "//src/ray/common:ray_config",
        "//src/ray/common:status",
        "//src/ray/protobuf:gcs_cc_proto",
        "//src/ray/protobuf:runtime_env_agent_cc_proto",
        "//src/ray/rpc/authentication:authentication_token_loader",
        "//src/ray/util:logging",
        "//src/ray/util:process",
        "//src/ray/util:time",
        "@boost//:beast",
        "@com_google_absl//absl/container:flat_hash_set",
        "@com_google_absl//absl/strings:str_format",
    ],
)

ray_cc_library(
    name = "local_object_manager_interface",
    hdrs = ["local_object_manager_interface.h"],
    visibility = [":__subpackages__"],
    deps = [
        "//src/ray/common:id",
        "//src/ray/common:ray_object",
        "//src/ray/protobuf:node_manager_cc_proto",
    ],
)

ray_cc_library(
    name = "local_object_manager",
    srcs = ["local_object_manager.cc"],
    hdrs = ["local_object_manager.h"],
    visibility = [":__subpackages__"],
    deps = [
        ":local_object_manager_interface",
        ":worker_pool",
        "//src/ray/common:asio",
        "//src/ray/common:id",
        "//src/ray/common:ray_object",
        "//src/ray/core_worker_rpc_client:core_worker_client_pool",
        "//src/ray/object_manager:object_directory",
        "//src/ray/protobuf:node_manager_cc_proto",
        "//src/ray/pubsub:subscriber_interface",
        "//src/ray/util:time",
    ],
)

ray_cc_library(
    name = "worker_killing_policy",
    srcs = [
        "worker_killing_policy.cc",
        "worker_killing_policy_group_by_owner.cc",
    ],
    hdrs = [
        "worker_killing_policy.h",
        "worker_killing_policy_group_by_owner.h",
    ],
    visibility = [":__subpackages__"],
    deps = [
        ":worker_interface",
        ":worker_pool",
        "//src/ray/common:lease",
        "//src/ray/common:memory_monitor",
        "@com_google_absl//absl/time",
    ],
)

ray_cc_library(
    name = "raylet_lib",
    srcs = [
        "node_manager.cc",
    ],
    hdrs = [
        "node_manager.h",
    ],
    linkopts = select({
        "@platforms//os:windows": [
        ],
        "//conditions:default": [
            "-lpthread",
        ],
    }),
    visibility = [":__subpackages__"],
    deps = [
        ":agent_manager",
        ":lease_dependency_manager",
        ":local_lease_manager",
        ":local_object_manager_interface",
        ":placement_group_resource_manager",
        ":runtime_env_agent_client",
        ":wait_manager",
        ":worker",
        ":worker_killing_policy",
        ":worker_pool",
        "//src/ray/common:buffer",
        "//src/ray/common:flatbuf_utils",
        "//src/ray/common:lease",
        "//src/ray/common:memory_monitor",
        "//src/ray/common/cgroup2:cgroup_manager_interface",
        "//src/ray/core_worker:experimental_mutable_object_provider",
        "//src/ray/core_worker_rpc_client:core_worker_client_pool",
        "//src/ray/flatbuffers:node_manager_generated",
        "//src/ray/gcs_rpc_client:gcs_client",
        "//src/ray/object_manager",
        "//src/ray/object_manager:ownership_object_directory",
        "//src/ray/object_manager/plasma:plasma_client",
        "//src/ray/pubsub:subscriber",
        "//src/ray/raylet/scheduling:scheduler",
        "//src/ray/rpc:node_manager_server",
        "//src/ray/rpc:rpc_callback_types",
        "//src/ray/rpc/authentication:authentication_token_loader",
        "//src/ray/stats:stats_lib",
        "//src/ray/util:cmd_line_utils",
        "//src/ray/util:container_util",
        "//src/ray/util:network_util",
        "//src/ray/util:throttler",
        "//src/ray/util:time",
        "@boost//:system",
        "@com_google_absl//absl/base:core_headers",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/container:flat_hash_set",
        "@com_google_absl//absl/memory",
        "@com_google_absl//absl/strings:str_format",
        "@com_google_absl//absl/time",
        "@com_google_googletest//:gtest_prod",
    ],
)

ray_cc_binary(
    name = "raylet",
    srcs = ["main.cc"],
    visibility = ["//visibility:public"],
    deps = [
        ":local_object_manager",
        ":local_object_manager_interface",
        ":raylet_lib",
        "//src/ray/common:asio",
        "//src/ray/common:lease",
        "//src/ray/common:ray_config",
        "//src/ray/common:status",
        "//src/ray/common/cgroup2:cgroup_manager_factory",
        "//src/ray/common/cgroup2:cgroup_manager_interface",
        "//src/ray/core_worker:metrics",
        "//src/ray/core_worker_rpc_client:core_worker_client",
        "//src/ray/core_worker_rpc_client:core_worker_client_pool",
        "//src/ray/gcs_rpc_client:gcs_client",
        "//src/ray/object_manager:ownership_object_directory",
        "//src/ray/object_manager_rpc_client:object_manager_client",
        "//src/ray/raylet/scheduling:cluster_lease_manager",
        "//src/ray/raylet_rpc_client:raylet_client_lib",
        "//src/ray/raylet_rpc_client:raylet_client_pool",
        "//src/ray/rpc:metrics_agent_client",
        "//src/ray/stats:stats_lib",
        "//src/ray/util:cmd_line_utils",
        "//src/ray/util:event",
        "//src/ray/util:process",
        "//src/ray/util:raii",
        "//src/ray/util:stream_redirection",
        "//src/ray/util:stream_redirection_options",
        "//src/ray/util:time",
        "@com_github_gflags_gflags//:gflags",
        "@com_google_absl//absl/strings",
        "@nlohmann_json",
    ],
)
